go to previous page   go to home page   go to next page

Answer:

Triangle() is activated with a parameter of 3.


New Activation

The statement:

    return N + Triangle( N-1 );

must have a value for Triangle(N-1) before the addition can be done. So the first activation of Triangle() causes a second activation of Triangle(), this time with a parameter of 3. See the picture.

two activations

QUESTION 14:

Look at the code again. Think about the latest activation. What does the activation Triangle(3) do?

int Triangle( int N )
{
  if ( N == 1 )
    return 1;
  else
    return N + Triangle( N-1 );
}